package cn.airnan.dg.service;

import cn.airnan.dg.configs.Global;
import cn.airnan.dg.entity.Player;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 玩家相关业务逻辑
 */
@Service
public class PlayerService {

    /**
     * 获取玩家列表
     *
     * @return
     */
    public Map<String, Player> getPlayers() {
        return Global.PLAYERS;
    }

    /**
     * 创建玩家
     *
     * @return
     */
    public Player createPlayer(Player player) {
        try {
            Global.PLAYERS.put(player.getId(), player);
            return player;
        }catch (Exception e){
            return null;
        }
    }

    /**
     * 判断是否可以创建玩家
     *
     * @return true/false
     */
    public boolean canCreatePlayer(String playerId) {
        boolean exist = Global.PLAYERS.containsKey(playerId);
        if (exist) {
            return false;
        }
        return true;
    }



}
